package com.wzk.travelspringboot.controller;

import com.wzk.travelspringboot.dto.OrderPayDTO;
import com.wzk.travelspringboot.dto.Result;
import com.wzk.travelspringboot.dto.TicketOrderDTO;
import com.wzk.travelspringboot.service.TicketOrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

/**
 * @Author: WangZiKang
 * @Date: 2025/1/19 16:21
 */

@Slf4j
@RestController
@RequestMapping("/ticket")
@RequiredArgsConstructor
public class TicketOrderController {

    private final TicketOrderService ticketOrderService;

    @PostMapping("/order")
    private Result createOrder(@Validated @RequestBody TicketOrderDTO dto){
        return ticketOrderService.createOrder(dto);
    }

    @PostMapping("/pay")
    public Result payStatus(@Validated @RequestBody OrderPayDTO dto){
        return ticketOrderService.changeOrderStatus(dto);
    }

    @GetMapping("/order/{userId}")
    public Result userOrder(@PathVariable(name = "userId") String userId){
        return ticketOrderService.queryOrderByUserId(Long.valueOf(userId));
    }

    @PutMapping("/cancel/{orderNumber}")
    public Result cancelOrder(@Validated @PathVariable(name = "orderNumber") @NotBlank(message = "订单号不能为空") String orderNumber){
        return ticketOrderService.cancelOrder(orderNumber);
    }




}
